﻿// Tool represents an image icon that performs some action when clicked
define([
    'Wjs/ui/elements/View'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'Tool',

        internal: {

            base: Wjs.getType('View'),

            initialize: function () {
                var me = this;

                me.setTag('span');

                me.addClass('wjs-tool');

                me.addEvents({

                    mousedown: function (evt) {

                        me.pressed = true; // Set the state of this tool as pressed so we don't deactivate the field editor when blurHandler

                        if (me.mouseDownHandler) {

                            me.mouseDownHandler(evt);
                        }
                    },

                    click: function (evt) {

                        me.pressed = false; // Finished pressing it

                        if (me.clickHandler) {

                            me.clickHandler(evt);
                        }
                    }
                });

            }
        },

        onMouseDown: function (fcn) {

            this.mouseDownHandler = Wjs.chain(this.mouseDownHandler, fcn);

            return this;
        },

        onClick: function (fcn) {

            this.clickHandler = Wjs.chain(this.clickHandler, fcn);

            return this;
        }

    });

});